<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>用给定的值填充数组</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.array-fill-keys.html">array_fill_keys</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.array-filter.html">array_filter</a></div>
 <div class="up"><a href="ref.array.html">数组 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.array-fill" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">array_fill</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.2.0, PHP 5)</p><p class="refpurpose"><span class="refname">array_fill</span> &mdash; <span class="dc-title">用给定的值填充数组</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.array-fill-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">array</span> <span class="methodname"><strong>array_fill</strong></span>
    ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$start_index</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$num</code></span>
   , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>
   )</div>

  <p class="para rdfs-comment">
   <span class="function"><strong>array_fill()</strong></span> 用 <em><code class="parameter">value</code></em>
   参数的值将一个数组填充 <em><code class="parameter">num</code></em> 个条目，键名由
   <em><code class="parameter">start_index</code></em> 参数指定的开始。
  </p>
   </div>
    
   
   <div class="refsect1 parameters" id="refsect1-function.array-fill-parameters">
    <h3 class="title">参数</h3>
    <p class="para">
     <dl>

      
      
       <dt>
<em><code class="parameter">start_index</code></em></dt>

       <dd>

        <p class="para">
         The first index of the returned array.
        </p>
        <p class="para">
         If <em><code class="parameter">start_index</code></em> is negative, 
         the first index of the returned array will be 
         <em><code class="parameter">start_index</code></em> and the following 
         indices will start from zero 
         (参见 <a href="function.array-fill.html#function.array-fill.example.basic" class="link">例子</a>)。
        </p>
       </dd>

      
      
      
       <dt>
<em><code class="parameter">num</code></em></dt>

       <dd>

        <p class="para">
         插入元素的数量。
         必须大于 0。
        </p>
       </dd>

      
      
      
       <dt>
<em><code class="parameter">value</code></em></dt>

       <dd>

        <p class="para">
         Value to use for filling
        </p>
       </dd>

      
      
     </dl>

    </p>
   </div>

   
   <div class="refsect1 returnvalues" id="refsect1-function.array-fill-returnvalues">
    <h3 class="title">返回值</h3>
    <p class="para">
     Returns the filled array
    </p>
   </div>

   
   <div class="refsect1 errors" id="refsect1-function.array-fill-errors">
    <h3 class="title">错误／异常</h3>
    <p class="para">
     如果 <em><code class="parameter">num</code></em> 少于一个，将会抛出 <strong><code>E_WARNING</code></strong>。
    </p>
   </div>

   
   <div class="refsect1 examples" id="refsect1-function.array-fill-examples">
    <h3 class="title">范例</h3>
    <p class="para">
     <div class="example" id="function.array-fill.example.basic">
      <p><strong>Example #1 <span class="function"><strong>array_fill()</strong></span> 例子</strong></p>
      <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$a&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_fill</span><span style="color: #007700">(</span><span style="color: #0000BB">5</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">6</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'banana'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$b&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_fill</span><span style="color: #007700">(-</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'pear'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$b</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
      </div>

      <div class="example-contents"><p>以上例程会输出：</p></div>
      <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [5]  =&gt; banana
    [6]  =&gt; banana
    [7]  =&gt; banana
    [8]  =&gt; banana
    [9]  =&gt; banana
    [10] =&gt; banana
)
Array
(
    [-2] =&gt; pear
    [0] =&gt; pear
    [1] =&gt; pear
    [2] =&gt; pear
)
</pre></div>
    </div>
   </div>
     </p>
   </div>

   
   <div class="refsect1 notes" id="refsect1-function.array-fill-notes">
    <h3 class="title">注释</h3>
    <p class="para">
     参见手册上 <a href="language.types.array.html" class="link">数组</a> 一节里关于负数的键的详细解释。
    </p>
   </div>

   
   <div class="refsect1 seealso" id="refsect1-function.array-fill-seealso">
    <h3 class="title">参见</h3>
    <p class="para">
     <ul class="simplelist">
      <li class="member"><span class="function"><a href="function.array-fill-keys.html" class="function" rel="rdfs-seeAlso">array_fill_keys()</a> - 使用指定的键和值填充数组</span></li>
      <li class="member"><span class="function"><a href="function.str-repeat.html" class="function" rel="rdfs-seeAlso">str_repeat()</a> - 重复一个字符串</span></li>
      <li class="member"><span class="function"><a href="function.range.html" class="function" rel="rdfs-seeAlso">range()</a> - 建立一个包含指定范围单元的数组</span></li>
     </ul>
    </p>
   </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.array-fill-keys.html">array_fill_keys</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.array-filter.html">array_filter</a></div>
 <div class="up"><a href="ref.array.html">数组 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
